﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;

namespace Milkify.Input
{
    [System.ComponentModel.TypeConverter(typeof(GenericKeyGestureConverter))]
    [System.Windows.Markup.ValueSerializer(typeof(GenericKeyGestureValueSerializer))]
    public class GenericKeyGesture : InputGesture
    {
        public Key Key { get; private set; }
        public ModifierKeys Modifiers { get; private set; }
        public string DisplayString { get; private set; }

        public GenericKeyGesture(Key key)
            : this(key, ModifierKeys.None)
        {
        }

        public GenericKeyGesture(Key key, ModifierKeys modifiers)
            : this(key, modifiers, string.Empty)
        {
        }

        public GenericKeyGesture(Key key, ModifierKeys modifiers, string displayString)
        {
            Key = key;
            Modifiers = modifiers;
            DisplayString = displayString;
        }

        public override bool Matches(object targetElement, InputEventArgs inputEventArgs)
        {
            KeyEventArgs keyEventArgs = inputEventArgs as KeyEventArgs;
            if (keyEventArgs == null)
                return false;
            return (Key == keyEventArgs.Key && Modifiers == Keyboard.Modifiers);
        }
    }
}
